﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using UtilZ.Dotnet.Ex.Base;
using UtilZ.Dotnet.Ex.Log;

namespace DotnetWinFormApp
{
    public partial class FTestLoger : Form
    {
        public FTestLoger()
        {
            InitializeComponent();
        }

        private void FTestLoger_Load(object sender, EventArgs e)
        {
            var redirectAppenderToUI = (RedirectAppender)Loger.GetAppenderByName(null, "RedirectToUI");
            if (redirectAppenderToUI != null)
            {
                redirectAppenderToUI.RedirectOuput += RedirectLogOutput;
            }
        }

        private void RedirectLogOutput(object sender, RedirectOuputArgs e)
        {
            logControl1.AddLog(e.Item.Content, e.Item.Level);

            //string str;
            //try
            //{
            //    str = string.Format("{0} {1}", DateTime.Now, e.Item.Content);
            //}
            //catch (Exception ex)
            //{
            //    str = ex.Message;
            //}

            //logControl.AddLog(str, e.Item.Level);
        }

        private void btnTest_Click(object sender, EventArgs e)
        {
            Loger.Trace("Trace");
            Loger.Debug("Debug");
            Loger.Warn("Warn");

            ILogerCore logerCore = Loger.GetLoger(null);
            if (logerCore != null)
            {
                logerCore.Info("Info");
                logerCore.Error("Error");
                logerCore.Fatal("Fatal");
            }
        }

        private void btnTestZLoger_Click(object sender, EventArgs e)
        {
            //UtilZ.Dotnet.Ex.ZLog.ZLoger.TestZLoger();
        }
    }
}
